package com.pb.b2b.model;

import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.Type;

import com.pb.b2b.model.enums.Status;

@Entity
@Table(name = "CATEGORY")
public class Category {

	private Long id;
	private Category parentCategory;
	private boolean top;
	private Status status;
	private int rowNumber;
	private boolean deleted;
	private Date dateAdded;
	private Date dateModified;
	private Set<CategoryLanguage> categoryLanguages = new HashSet<CategoryLanguage>(0);
	private Set<Product> products = new HashSet<Product>(0);

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column(name = "ID", nullable = false, unique = true)
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "PARENT_ID", nullable = true)
	public Category getParentCategory() {
		return parentCategory;
	}

	public void setParentCategory(Category parentCategory) {
		this.parentCategory = parentCategory;
	}

	@Column(name = "TOP", nullable = false)
	public final boolean isTop() {
		return top;
	}

	public final void setTop(boolean top) {
		this.top = top;
	}

	@Column(name = "STATUS", nullable = false)
	public Status getStatus() {
		return status;
	}

	public void setStatus(Status status) {
		this.status = status;
	}

	@Column(name = "ROW_NUMBER")
	public int getRowNumber() {
		return rowNumber;
	}

	public void setRowNumber(int rowNumber) {
		this.rowNumber = rowNumber;
	}

	@Column(name = "DELETED", nullable = false)
	@Type(type = "org.hibernate.type.BooleanType")
	public boolean isDeleted() {
		return deleted;
	}

	public void setDeleted(boolean deleted) {
		this.deleted = deleted;
	}

	@Column(name = "DATE_ADDED", nullable = false)
	public final Date getDateAdded() {
		return dateAdded;
	}

	public final void setDateAdded(Date dateAdded) {
		this.dateAdded = dateAdded;
	}

	@Column(name = "DATE_MODIFIED", nullable = false)
	public final Date getDateModified() {
		return dateModified;
	}

	public final void setDateModified(Date dateModified) {
		this.dateModified = dateModified;
	}

	@OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, mappedBy = "category")
	public Set<CategoryLanguage> getCategoryLanguages() {
		return categoryLanguages;
	}

	public void setCategoryLanguages(Set<CategoryLanguage> categoryLanguages) {
		this.categoryLanguages = categoryLanguages;
	}

	@ManyToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, mappedBy = "categories")
	public Set<Product> getProducts() {
		return products;
	}

	public void setProducts(Set<Product> products) {
		this.products = products;
	}

}
